<%@ page language="java" pageEncoding="utf-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>影厅资料列表</title>
    <jsp:include page="/IncludeJS.jsp"></jsp:include>
</head>
<body>
<script type="text/javascript">
    $(function () {
        var pager = $(".easyui-datagrid").datagrid('getPager');
        $(pager).pagination({
            total:${pager.totalRows},
            pageSize:${pager.pageRow},
            displayMsg: '{from}-{to}/{total}',
            pageNumber:${pager.cur_page},
            afterPageText: '页，共{pages}页',
            pageList: [100, 500, 1000, 10000],
            loading: false,
            showPageList: true,
            showRefresh: true,
            //刷新方法
            onBeforeRefresh: function (p, s) {
                location.href = "${pageContext.request.contextPath }/movieHall/list?cur_page=" + p + "&pageRow=" + s;
            },
            onSelectPage: function (p, s) {
                location.href = "${pageContext.request.contextPath }/movieHall/list?cur_page=" + p + "&pageRow=" + s;
            }
        });
        $('#changesize').datagrid('resize', {
            height: document.body.clientHeight - 44,
            width: document.body.clientWidth - 1
        });
    });

    function getRowData(value, rec) {
        var id = rec.id;

    }

    function save() {
        document.forms[1].submit();
    }

    function check() {

    }

    function add() {
        var url = "${pageContext.request.contextPath }/movieHall/init";
        //var title="区域新增";
        //addTab1(title, url);
        window.location.href = url;

    }

    function del() {
        var ids = $('input[name="id"]:checked');
        var len = ids.length;
        if (ids.length == 0) {
            alert("请选择要删除的影厅");
            return;
        }
        if (!confirm('删除确认')) {
            return;
        }
        var arr = "";
        ids.each(function (i, d) {
            if ((i + 1) != len) {
                arr += $(d).val() + ",";
            } else {
                arr += $(d).val();
            }
        })
        var url = "${pageContext.request.contextPath }/movieHall/del?ids=" + arr;
        location.href = url;
    }

    function edit() {
        var ids = $('input[name="id"]:checked');
        var len = ids.length;
        if (ids.length == 0) {
            alert("请选择要修改的影厅");
            return;
        }
        url = "${pageContext.request.contextPath }/movieHall/update?hallId=" + ids[0].value;
        location.href = url;

    }

    if ("${msg}" != null && "${msg}".length > 0) {
        alert("${msg}");
    }

    function seat() {
        var row = $("#changesize").datagrid("getSelected");
        var url = "${pageContext.request.contextPath }/movieHall/seat?hallId=" + row.id + "&seatNum=" + row.seatNum;
        var title = "安排【" + row.hallName + "】座位表";
        addTab1(title, url);

    }

    function reSeat() {
        var row = $("#changesize").datagrid("getSelected");
        alert(row.seatNum);
        var url = "${pageContext.request.contextPath }/movieHall/reSeat?hallId=" + row.id + "&seatNum=" + row.seatNum;
        var title = "安排【" + row.hallName + "】座位表";
        addTab1(title, url);

    }

</script>

<form action="${pageContext.request.contextPath }/movieHall/list" method="post" onsubmit="check();">
    <table width="100%" border="0" cellpadding="0" cellspacing="0" BACKGROUND="images/maintitle.jpg" class="tablelist2">
        <tr>
            <td align="left" class="tableselect2">
                <div class="tools">
                    <ul class="toolbar">
                        <li><a href="javascript:void(0);" onclick="add();"><span><img
                                src="${pageContext.request.contextPath }/images/add.png"></span>添加</a></li>
                        <li><a href="javascript:void(0);" onclick="edit();"><span><img
                                src="${pageContext.request.contextPath }/images/Mod.png"></span>修改</a></li>
                        <li><a href="javascript:void(0);" onclick="del();"><span><img
                                src="${pageContext.request.contextPath }/images/delete.png"></span>删除</a></li>
                        <li><a href="javascript:void(0);" onclick="seat();"><span><img
                                src="${pageContext.request.contextPath }/images/buy.png"></span>安排座位</a></li>
                        <li><a href="javascript:void(0);" onclick="reSeat();"><span><img
                                src="${pageContext.request.contextPath }/images/buy.png"></span>重新生成座位</a></li>
                    </ul>
                </div>
            </td>
            <td align="right" class="tableselect2">
                影院名称
                <select name="agentId" id="agentId" style="width:300px">
                    <option value="0">---不选择---</option>
                    <c:forEach var="v" items="${agentList}">
                        <c:if test="${v.agentId==movieHall.agentId}">
                            <option value="${v.agentId}" selected>${v.agentName}</option>
                        </c:if>
                        <c:if test="${v.agentId!=movieHall.agentId}">
                            <option value="${v.agentId}">${v.agentName}</option>
                        </c:if>
                    </c:forEach>
                </select>
                <input type="text" name="agentName" id="agentName" cssStyle="width:200px"
                       onkeyup="changeAgent2(this.value);"></input>
                <input type="submit" value="  查 询  ">
            </td>
        </tr>
    </table>
</form>


<table class="easyui-datagrid" pagination="true" id="changesize" style="width:auto;padding:0px" singleSelect="false"
       data-options="onClickRow:getRowData">
    <thead>
    <tr>
        <th field="id" checkbox="true" width=50>选择</th>
        <th field="hallName" width=100 align="center">影厅名称</th>
        <th field="agentName" width=200 align="center">机构名称</th>
        <th field="hallTypeName" width=150 align="center">影厅类型</th>
        <th field="seatNum" width=150 align="center">座位数</th>
        <th field="row" width=150 align="center">总排数</th>
        <th field="col" width=150 align="center">座位数/排</th>
        <th field="state" width=80 align="center">状态</th>
        <th field="remark" width=150 align="center">说明</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${pager.data}" var="v">
        <tr>
            <td>${v.hallId }</td>
            <td>${v.hallName }</td>
            <td>${v.agentName }</td>
            <td>${v.hallTypeName }</td>
            <td>${v.seatNum}</td>
            <td>${v.row }</td>
            <td>${v.col }</td>
            <td>
                <c:if test="${v.state==0}">不可用</c:if>
                <c:if test="${v.state==1}">可用</c:if>
            </td>
            <td>${v.remark}</td>
        </tr>
    </c:forEach>
    </tbody>
</table>
</body>
<script type="text/javascript">
    var orgjson = {"data": []};

    function initAgentJson() {
        $("#agentId option").each(function () {
            var item = {"value": this.value, "text": this.text};
            orgjson.data.push(item);
        });
    }

    initAgentJson();

    function changeAgent2(value) {
        $("#agentId").empty();
        $.each(orgjson.data, function (i, item) {
            if (item["text"].indexOf(value) >= 0) {
                $("#agentId").append("<option value='" + item["value"] + "'>" + item["text"] + "</option>");
            }
        });
    }
</script>
</html>